package com.mew.user.controller;

import com.mew.common.dc.mapper.FriendMapper;
import com.mew.common.rest.user.EnterInfoResponse;
import com.mew.common.rest.user.SimpleUserResponseMessage;
import com.mew.mail.service.MailService;
import com.mew.sys.BulletinController;
import com.mew.user.events.OnlineGiftController;
import com.mew.user.events.service.UserSignService;
import com.mew.user.service.FriendService;
import com.mew.user.service.OnlineGiftService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private OnlineGiftService onlineGiftService;
    @Autowired
    private BulletinController bulletinController;
    @Autowired
    private UserSignService userSignService;
    @Autowired
    private MailService mailService;
    @Autowired
    private FriendService friendService;

    @ResponseBody
    @RequestMapping("/enter/{uid}")
    public EnterInfoResponse enter(@PathVariable("uid")long uid){
        EnterInfoResponse enterInfoResponse = new EnterInfoResponse();

        //在线时间
        enterInfoResponse.setOnlineTime(onlineGiftService.refreshOnlineGift(uid).getReceiveType().indexOf("1")>-1?1:0);
        //公告
        enterInfoResponse.setBulletin(bulletinController.getBulletins(uid).size()>0?1:0);
        //签到
        enterInfoResponse.setSign(userSignService.signInfo(uid).getSign()==1?0:1);
        //未读邮件
        Integer mailCount = mailService.getMailCount(uid);
        enterInfoResponse.setMail( mailCount != null && mailCount > 0 ? 1 : 0);
        //好友申请
        enterInfoResponse.setFriendApply(friendService.hasApply(uid));
        return enterInfoResponse;
    }

}
